<?php

$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setTitle("title")->setDescription("description");
                        
// Assign cell values
$objWorksheet = $objPHPExcel->getActiveSheet();

//no column, no baris, isi
$objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn(0)->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn(1)->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn(2)->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn(3)->setAutoSize(true);
// $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn(4)->setAutoSize(true);
$objPHPExcel->setActiveSheetIndex()->mergeCells('A1:D1')->setCellValue('A1', 'Data Prestasi Mahasiswa');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, 6, 'No');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, 6, 'Nama Kegiatan');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, 6, 'Tanggal Kegiatan');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, 6, 'Keterangan');
$objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
$objPHPExcel->getActiveSheet()->getStyle('A6')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('B6')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('C6')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('D6')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
// $objPHPExcel->getActiveSheet()->getStyle('E3')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('A6')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('B6')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('C6')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('D6')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
// $objPHPExcel->getActiveSheet()->getStyle('E3')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('A6')->getFill()->getStartColor()->setARGB('bebebf');
$objPHPExcel->getActiveSheet()->getStyle('B6')->getFill()->getStartColor()->setARGB('bebebf');
$objPHPExcel->getActiveSheet()->getStyle('C6')->getFill()->getStartColor()->setARGB('bebebf');
$objPHPExcel->getActiveSheet()->getStyle('D6')->getFill()->getStartColor()->setARGB('bebebf');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, 3, 'Nama');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, 4, 'NRP');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, 3, $mahasiswa["NAMA"]);
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, 4, $mahasiswa["NRP"]);
// $objPHPExcel->getActiveSheet()->getStyle('E3')->getFill()->getStartColor()->setARGB('bebebf');
$a	= 7;
$no = 1;
// $b	= 0;
// $c	= 2;
foreach($query as $row){
	$objPHPExcel->getActiveSheet()->getRowDimension($a)->setRowHeight(25);
	$objPHPExcel->getActiveSheet()->getStyle('A'.$a)->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
	$objPHPExcel->getActiveSheet()->getStyle('B'.$a)->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
	$objPHPExcel->getActiveSheet()->getStyle('C'.$a)->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
	$objPHPExcel->getActiveSheet()->getStyle('D'.$a)->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
	// $objPHPExcel->getActiveSheet()->getStyle('E'.$a)->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
	$objPHPExcel->getActiveSheet()->getStyle('A'.$a)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
	$objPHPExcel->getActiveSheet()->getStyle('B'.$a)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
	$objPHPExcel->getActiveSheet()->getStyle('C'.$a)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
	$objPHPExcel->getActiveSheet()->getStyle('D'.$a)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
	// $objPHPExcel->getActiveSheet()->getStyle('E'.$a)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $a, $no);
	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $a, $row["NAMA_KEGIATAN"]);
	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $a, date("d-m-Y",strtotime($row["TANGGAL_KEGIATAN"])));
	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $a, $row["KETERANGAN"]);
	// $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, $a, ($row["STATUS"] == 0) ? ("Belum Lulus") : (($row["STATUS"] == 1) ? ("Lulus") : (($row["STATUS"] == 2) ? ("DO") : ("Cuti"))));
	$no++;
	$a++;
}
// Save it as an excel 2003 file
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header("Content-Disposition: attachment;filename='Cetak Prestasi Mahasiswa.xlsx'");
header('Cache-Control: max-age=0');
$objWriter = IOFactory::createWriter($objPHPExcel, 'Excel2007');
// $objWorksheet->addChart($chart);
$objWriter->setIncludeCharts(TRUE);
$objWriter->save('php://output');
?>